# Contributor: Prokop Randáček <prokop@rdck.dev>
# Maintainer: Prokop Randáček <prokop@rdck.dev>
pkgname=tup
pkgver=0.7.11
pkgrel=0
pkgdesc="A file-based build system"
url="http://gittup.org/tup"
arch="all"
license="GPL-2.0-only"
makedepends="fuse3-dev pcre-dev inih-dev sqlite-dev"
checkdepends="sqlite ccache"
subpackages="$pkgname-doc $pkgname-vim::noarch"
source="$pkgname-$pkgver.tar.gz::https://github.com/gittup/tup/archive/refs/tags/v$pkgver.tar.gz
	s390x_risc3264_support.patch
	system_inih.patch
	loongarch64_support.patch
	"
options="!check" # tests need to run tup, which requires fuse

prepare() {
	default_prepare

	sed "s/\`git describe\`/$pkgver/" -i src/tup/link.sh
	echo "CFLAGS += $CFLAGS" >> Tuprules.tup
	echo "LDFLAGS += $LDFLAGS" >> Tuprules.tup
	echo "CONFIG_TUP_USE_SYSTEM_INIH=y" >> tup.config
	echo "CONFIG_TUP_USE_SYSTEM_SQLITE=y" >> tup.config
}

build() {
	# fuse not available so ./bootstrap.sh does not work
	./build.sh
	./build/tup init
	./build/tup generate runme.sh
	./runme.sh
}

vim() {
	pkgdesc="$pkgname (vim syntax)"
	install_if="$pkgname=$pkgver-r$pkgrel vim"
	depends=

	amove usr/share/vim
}

package() {
	install -D -m755 tup "$pkgdir"/usr/bin/tup
	install -D -m644 tup.1 -t "$pkgdir"/usr/share/man/man1
	install -D -m644 contrib/syntax/tup.vim -t "$pkgdir"/usr/share/vim/vimfiles/syntax

	mkdir -p "$pkgdir"/usr/share/vim/vimfiles/ftdetect
	echo 'au BufNewFile,BufRead Tupfile,*.tup setf tup' > "$pkgdir"/usr/share/vim/vimfiles/ftdetect/tup.vim
}

sha512sums="
b923366bb15ce6e5be027b6b3e98b1029cd7dbe6ce2a8dd37a8e4b71521c8ff6d95d88fe296f5ca4719bbc048c6aaa5eacdd8cac1410d46df54ac674d6fd8aee  tup-0.7.11.tar.gz
733282451020ae770e2ae3230f30df8b9ba10bbfe8f1e151f04d45819c4af9c425617c81fd24b0030a4fc530607bd9806ec69033e85eef7db013266648e0ebf2  s390x_risc3264_support.patch
ae4c4fc929b3974945ca7c9f7bac51d9e78168497e932892f0dfc879499fea43255a2b02ff650e661d2019a60aeb03504743cef48f58b2c389076400012c257a  system_inih.patch
5a074fe5f6070f4f9e0816a357db93b7799de04fb4a20d47af59beb327fbfef4d9bf6f22eb83613054380cba8a56cfec9099ff371de592324f382d89295e675a  loongarch64_support.patch
"
